const express = require('express');
const router = express.Router();
const { createCaptcha } = require("../service/captchaService");
const { formatResponseBody } = require("../utils/tools");

router.get("/", (req, res, next) => {
    // 1. 生成验证码
    const captcha = createCaptcha();

    // 2. 将文本保存到session中
    req.session.captchaText = captcha.text;

    // 3. 将图片数据响应给客户端
    res.set("Content-Type", "image/svg+xml");
    res.send(captcha.data);
})

module.exports = router;